package cn.wf.product.client;

import cn.wf.product.DecreaseStockInput;
import cn.wf.product.ProductInfoOutput;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * Feign结合Hystrix使用,配置fallback如果下面两个方法产生服务降级，就会对应执行ProductClientFallback里面两个重写方法
 * Created by 廖师兄
 * 2017-12-10 21:04
 */
@FeignClient(name = "product", fallback = ProductClient.ProductClientFallback.class)
public interface ProductClient {

    @PostMapping("/product/listForOrder")
    List<ProductInfoOutput> listForOrder(@RequestBody List<String> productIdList);

    @PostMapping("/product/decreaseStock")
    void decreaseStock(@RequestBody List<DecreaseStockInput> decreaseStockInputList);

    @Component  //使用这个注解将该类注入到spring容器中，提供给order服务使用，在order的启动类里面要扫描@ComponentScan(basePackages = "cn.wf")才能使用
    static class ProductClientFallback implements ProductClient {

        @Override
        public List<ProductInfoOutput> listForOrder(List<String> productIdList) {
            return null;
        }

        @Override
        public void decreaseStock(List<DecreaseStockInput> decreaseStockInputList) {

        }
    }
}
